# ================账⼾表====================
use test_1;
DROP TABLE bank_account;
CREATE TABLE bank_account (
 id bigint PRIMARY KEY AUTO_INCREMENT, 
 name varchar(255) NOT NULL, # 姓名
 balance decimal(10, 2) NOT NULL # 余额
);
INSERT INTO bank_account(`name`, balance) VALUES('张三', 1000);
INSERT INTO bank_account(`name`, balance) VALUES('李四', 1000);
update bank_account set balance = balance -100 where name = '张三';
update bank_account set balance = balance + 100 where name = '李四';

# 开启事务
start transaction;
# 或
begin

commit # 提交事务，并对更改持久化保存

rollback  # 回滚事务，取消之前的修改，恢复原样



start transaction;
update bank_account set balance = balance -100 where name = '张三';
savepoint savepoint1;
SELECT * FROM bank_account;

update bank_account set balance = balance + 100 where name = '李四';
SAVEPOINT savepoint2;
SELECT * FROM bank_account;

ROLLBACK to savepoint1;


begin;

INSERT INTO bank_account(`name`, balance) VALUES('王五', 1000);
INSERT INTO bank_account(`name`, balance) VALUES('赵六', 1000);


INSERT INTO bank_account(`name`, balance) VALUES('钱七', 1000);
INSERT INTO bank_account(`name`, balance) VALUES('王麻子', 1000);

SELECT @@global.transaction_isolation;
SELECT @@session.transaction_isolation;

set global transaction_isolation = 'read-uncommitted';
set global transaction_isolation = 'read-committed';
set global transaction_isolation = 'repeatable-read';
set global transaction_isolation = 'serializable';
set session transaction_isolation = 'repeatable-READ';

# 方法二:
set @@global.transaction_isolation = 'repeatable-read';


START TRANSACTION;
INSERT INTO bank_account(id,`name`, balance) VALUES(3,'王五', 1000);
SELECT * FROM bank_account;
COMMIT;





















